package com.example.demo.zhoushengwen.response;

import lombok.ToString;

@ToString
public enum CommonCode implements ResultCode
{
    
    SUCCESS(true, 111, "操作成功！"), FAIL(false, 222, "操作失败！"), FORESEE_EXCEPTION(false, 333, "预知异常"), PARSE_JSON_EXCEPTION(
        false, 888, "解析json异常"), METHODNOTSUPPORTED(false, 10000,
            "程序不支持该方法"), NOT_FOUND(false, 404, "没有找到接口"), other_error(false, 1010, "未定义的错误");
    
    boolean success;
    
    //操作代码
    int code;
    
    //提示信息
    String message;
    
    private CommonCode(boolean success, int code, String message)
    {
        this.success = success;
        this.code = code;
        this.message = message;
    }
    
    public static CommonCode getCode(int code)
    {
        for (CommonCode enumcode : CommonCode.values())
        {
            if (enumcode.code == code)
                return enumcode;
        }
        
        return other_error;
    }
    
    @Override
    public boolean success()
    {
        return success;
    }
    
    @Override
    public int code()
    {
        return code;
    }
    
    @Override
    public String message()
    {
        return message;
    }
    
}
